package com.qidian.buy.controller;

import com.qidian.buy.pojo.ContentCategory;
import com.qidian.buy.service.ContentCategoryService;
import com.qidian.buy.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2023/9/6 10:58
 */
@RestController
@RequestMapping("/contentCategory")
public class ContentCategoryController {
    @Autowired
    private ContentCategoryService contentCategoryService;

    @GetMapping("/hasChildren")
    public QdResult hasChildren(Long parentId){
        return contentCategoryService.queryCountByParentId(parentId);
    }

    @PostMapping("/save")
    public QdResult save(@RequestBody ContentCategory category){
        return contentCategoryService.save(category);
    }

    @GetMapping("/queryByParentId")
    public QdResult queryByParentId(Long parentId, @RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "10") int limit){
        return contentCategoryService.queryByParentId(parentId,page,limit);
    };
}
